<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{ title }}</title>
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .form-section, .list-section {
            padding: 20px;
            border-radius: 8px;
        }
        .form-section {
            background-color: #f8f9fa;
            border: 1px solid #e9ecef;
        }
        .list-section {
            background-color: #ffffff;
            border: 1px solid #dee2e6;
        }
        .navbar {
            margin-bottom: 20px;
        }
    </style>
</head>
<body>
    <nav class="navbar navbar-expand-lg navbar-light bg-light">
        <a class="navbar-brand" href="/">饮水机数据记录</a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav">
                <li class="nav-item">
                    <a class="nav-link" href="/">首页</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/predict">猜一猜</a>
                </li>
            </ul>
        </div>
    </nav>

    <div class="container mt-5">
        <div class="row">
            <div class="col-md-4">
                <div class="form-section">
                    <h2 class="mb-4">记录数据</h2>
                    <form action="/submit" method="post">
                        <div class="form-group">
                            <label for="test_date">日期:</label>
                            <input type="date" id="test_date" name="test_date" class="form-control" value="{{ today }}" required>
                        </div>
                        <div class="form-group">
                            <label for="test_time">时间:</label>
                            <input type="time" id="test_time" name="test_time" class="form-control" value="{{ current_time }}" required>
                        </div>
                        <div class="form-group">
                            <label for="water_level">储水量百分比:</label>
                            <select id="water_level" name="water_level" class="form-control" required>
                                <option value="0">0%</option>
                                <option value="20">20%</option>
                                <option value="40">40%</option>
                                <option value="60">60%</option>
                                <option value="80">80%</option>
                                <option value="100">100%</option>
                            </select>
                        </div>
                        <button type="submit" class="btn btn-primary btn-block">提交</button>
                    </form>
                </div>
            </div>
            <div class="col-md-8">
                <div class="list-section">
                    <h2 class="mb-4">已记录数据</h2>
                    <form method="get" action="/" class="mb-4">
                        <div class="form-row">
                            <div class="col">
                                <label for="start_date">开始日期:</label>
                                <input type="date" id="start_date" name="start_date" class="form-control" value="{{ start_date }}" required>
                            </div>
                            <div class="col">
                                <label for="end_date">结束日期:</label>
                                <input type="date" id="end_date" name="end_date" class="form-control" value="{{ end_date }}" required>
                            </div>
                            <div class="col align-self-end">
                                <button type="submit" class="btn btn-secondary btn-block">筛选</button>
                            </div>
                        </div>
                    </form>
                    <table class="table table-bordered">
                        <thead class="thead-light">
                            <tr>
                                <th>序号</th>
                                <th>日期</th>
                                <th>时间</th>
                                <th>储水量百分比</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for row in data %}
                            <tr>
                                <td>{{ row[0] }}</td> <!-- 这里使用序号 -->
                                <td>{{ row[2] }}</td>
                                <td>{{ row[3] }}</td>
                                <td>{{ row[4] }}%</td>
                                <td>
                                    <form action="/delete/{{ row[1] }}" method="post">
                                        <button type="submit" class="btn btn-danger btn-sm">删除</button>
                                    </form>
                                </td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                    <nav aria-label="Page navigation">
                        <ul class="pagination justify-content-center">
                            {% if page > 1 %}
                            <li class="page-item">
                                <a class="page-link" href="/?start_date={{ start_date }}&end_date={{ end_date }}&page={{ page - 1 }}">上一页</a>
                            </li>
                            {% endif %}
                            {% if page < total_pages %}
                            <li class="page-item">
                                <a class="page-link" href="/?start_date={{ start_date }}&end_date={{ end_date }}&page={{ page + 1 }}">下一页</a>
                            </li>
                            {% endif %}
                        </ul>
                    </nav>
                </div>
            </div>
        </div>
    </div>
    <script src="{{ url_for('static', filename='js/jquery-3.7.1.min.js') }}"></script>
    <script src="{{ url_for('static', filename='js/bootstrap.js') }}"></script>
</body>
</html>
